package com.zhk.ScriptManagement.service.impl;

import com.zhk.ScriptManagement.constant.ShiroConstant;
import com.zhk.ScriptManagement.entity.Permission;
import com.zhk.ScriptManagement.entity.User;
import com.zhk.ScriptManagement.entity.vo.UserVo;
import com.zhk.ScriptManagement.mapper.PermissionMapper;
import com.zhk.ScriptManagement.mapper.UserMapper;
import com.zhk.ScriptManagement.service.PermissionService;
import com.zhk.ScriptManagement.util.CodeMsg;
import com.zhk.ScriptManagement.util.RedisUtil;
import com.zhk.ScriptManagement.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @Author: zhouhongkun
 * @Description: 权限实现类
 * @Date: 2021/4/4 17:43
 */
@Service
public class PermissionServiceImpl implements PermissionService {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private PermissionMapper permissionMapper;



    @Override
    public Result updatePermission(Permission permission) {
        try{
            RedisUtil.del(ShiroConstant.ROLE_SHIRO_CACHE + permission.getUserId());
            permissionMapper.updatePermission(permission);
            return Result.success("更新成功");
        }catch (Exception e){
            log.error(e.getMessage());
            return Result.error(CodeMsg.SERVER_EXCEPTION,"更新失败");
        }
    }
}
